
<?php
error_reporting(E_ALL);

include_once('../controller/includes/db_access.php');

if ((isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '')) == 'multiple') {

    $first_name =  stripslashes($_POST['vn']);
    $last_name  =  stripslashes($_POST['an']);
    $compagny   =  stripslashes($_POST['compagny']);
    $email      =  stripslashes($_POST['email']);


// Insert a new user into the `user` table  
    $q = new Query;
    $q
            ->insert_into('`newsletter`', array(
                '`first_name`' => $first_name,
                 '`last_name`' => $last_name,
                 '`compagny`' => $compagny,
                 '`email`' => $email,
                    )
    );

    $result = $q->run();
    $newsletter_id = $q->get_insert_id();
    if ($result && $newsletter_id > 0) {

        //$Error = '<font color="green">successful : categorie is toegevoed</font>';
               header('Location: newsletter_list.php');
    } else {

        $Error = '<font color="red">Error: categorie is niet toegevoed</font>';
  
           
    }
}
?>
<html>
<head>
<meta charset="utf-8" />
<!--[if lt IE 9]>
<script
src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" href="styles/style.css" type="text/css" />
<!--[if lte IE 7]>
<link rel="stylesheet" href="style_ie.css" />
<![endif]-->
<title>dbme!!!!</title>
</head>
<body>
<div id="bloc_page">
<header>

</header>  
 <nav>
    <?php include_once('header.php'); ?>
</nav>
 <section>

    <article>
        
          <table>
                <tr>
                 <td colspan="7" class="title" style="width: 100%;">Mail list</td>
                </tr>
                <tr>
                    <td colspan="7" class="title" style="width: 100%;"><div><a href="newsletter.php" >Send een nieuws bericht</a></div></td>
                </tr>
                <tr  class="second">
                <td style="width: 15%;">Voornaam</td>
                <td style="width: 15%;">Achternaam</td>
                <td style="width: 15%;">Bedrijf</td>
                <td style="width: 25%;">Email</td>
                <td style="width: 10%;">Aktief </td>
                <td style="width: 10%;"></td>
                <td style="width: 10%;"></td>
                </tr>
                <?php
// put your code here
                $q = new Query;
                $q
                        ->select('*'
                        )
                        ->from('`newsletter`')
                        ->order_by(
                                array(
                                    '`newsletter`.`first_name` ASC',
                                )
                        )
                        ->run();

                $result = $q->run();
                $count = $q->get_selected_count();

                if (!($result && $count > 0)) {
                    echo 'No users found.' . "\n";
                } else {
                    while ($rows = mysql_fetch_object($result)) {

            echo'<tr  class="second">
                <td style="width: 15%;">' . $rows->first_name . '</td>
                <td style="width: 15%;">' . $rows->last_name . '</td>
                <td style="width: 15%;">' . $rows->compagny . '</td>
                <td style="width: 25%;">' . $rows->email . '</td>
                <td style="width: 10%; text-align: center;">' . $rows->aktief . '</td>
                <td style="width: 10%; text-align: center;"><a href="newsletter_edit.php?pid=' . $rows->newsletter_id . '">detail</a></td>
                <td style="width: 10%; text-align: center;"><a href="newsletter_del.php?pid=' . $rows->newsletter_id . '">delete</a></td></tr>';
                    }
                }
                ?>
                
                  <tr>
                 <td colspan="7">
                  <form name="form1" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
                   <input type="hidden" name="action" value="multiple" />  
                    <fieldset style="text-align:left; padding:24px;"> 
                    <legend>Subscribe to Our Newsletter &nbsp;</legend> 
                    <br />
                    Voornaam:<br />
                    <input name="vn" type="text" maxlength="36" value="" /><br />
                    Achternaam:<br />
                    <input name="an" type="text" maxlength="36" value="" /><br />
                    Email:<br />
                    <input name="email" type="email" maxlength="36" value="" /><br /><br />
                    Bedrijf:<br />
                    <input name="compagny" type="text" maxlength="36" value="" /><br /><br /> 
                    <input type="submit" value="save" name="save" />
                    </fieldset> 
                    </form>
                 </td>
                </tr>
       



            </tbody>
        </table>
    </article>

</section>
 
 <footer>  
<p>Lorem ipsum dolor sit amet...</p>
<p>Vivamus sed libero nec mauris pulvinar facilisis ut non sem...</p>
<p>Phasellus ligula massa, congue ac vulputate non, dignissim at augue...</p>
</footer>
</div>
</body>
</html>

 